﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Wicresoft.Busi.BizLogic;
using Wicresoft.Busi.Entity;
using Wicresoft.Framework.Organization;
using Wicresoft.Common;

public partial class NewMeetingRoom_RoomApplyApprove : BaseAuthenticationPage
{
    public string SearchDefaultText
    {
        get
        {
            return "搜索 会议名称或会议室";
        }
    }

    protected void Page_Load(object sender, System.EventArgs e)
    {
        this.tbSearch.Attributes.Add("onfocus", string.Format("clearText(this, '{0}');", SearchDefaultText));
        this.tbSearch.Attributes.Add("onblur", string.Format("insertText(this, '{0}');", SearchDefaultText));
        this.tbSearch.Attributes.Add("onkeydown", "return searchClick();");

        if (!IsPostBack)
        {
            tbSearch.Text = SearchDefaultText;

            this.Order.OrderColumn = "ApplyDate";//vwMeetingRoomApply.SQLCOL_APPLYDATE ;
            this.Order.OrderDirection = "ASC";
            BindData();
        }
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {


    }

    protected override void Pager_PageChanged(object sender, EventArgs e)
    {
        BindData();
        base.Pager_PageChanged(sender, e);
    }

    protected override void Order_OrderChanged(object sender, EventArgs e)
    {
        BindData();
        base.Order_OrderChanged(sender, e);
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }

    private void BindData()
    {

        //Wicresoft.Common.PagingEntity pe = new Wicresoft.Common.PagingEntity();
        //pe.PageIndex = this.Pager.PageIndex;
        //pe.PageSize = this.Pager.PageSize;
        //pe.TableName = "vwMeetingRoomApply2";
        //pe.SelectString = "*";
        //if (this.Order.OrderDirection.ToLower().Contains("desc"))
        //{
        //    pe.DescString = this.Order.OrderColumn + " DESC";
        //    pe.AscString = this.Order.OrderColumn + " ASC";
        //}
        //else
        //{
        //    pe.DescString = this.Order.OrderColumn + " ASC";
        //    pe.AscString = this.Order.OrderColumn + " DESC";
        //}

        //DataTable dt = BLMeetingRoomApply.GetUnAuditMeetingRoomApply(CurrentUser.Name, pe);
        string whereClause = "(Status='" + MeetingStatus.POST + "')";
        if (OrganizationPublicHelper.IsUserInRole(CurrentUser.ID, Wicresoft.Busi.Entity.MeetingRoles.Manage))
            whereClause += "";
        else
            whereClause += " AND Applicant='" + CurrentUser.Name + "'";
        if (this.tbSearch.Text.Trim() != "" && tbSearch.Text != SearchDefaultText)
            whereClause += " AND (Topic like '%" + this.tbSearch.Text.Trim().Replace("'", "").Replace("%", "[%]") + "%' or RoomName like '%" + this.tbSearch.Text.Trim().Replace("'", "").Replace("%", "[%]") + "%')";

        if (this.txtDateFrom.Text.Trim() != "")
            whereClause += " AND ApplyDate >='" + this.txtDateFrom.Text.Trim() + "' AND ApplyDate<'" + Convert.ToDateTime(this.txtDateFrom.Text.Trim()).AddDays(1) + "' ";

        if (this.txtDateTo.Text.Trim() != "")
            whereClause += " AND MeetingDate >='" + this.txtDateTo.Text.Trim() + "' AND MeetingDate<'" + Convert.ToDateTime(this.txtDateTo.Text.Trim()).AddDays(1) + "' ";

        int RecordCount = 0;
        DataTable dt = DataAccess.Select(typeof(Wicresoft.JDPostBoard.Entity.vwMeetingRoomApply2), this.Pager.PageIndex, this.Pager.PageSize, whereClause, this.Order.OrderColumn + " " + this.Order.OrderDirection, ref RecordCount);

        foreach (DataRow dr in dt.Rows)
        {
            if (dr[Wicresoft.Busi.Entity.MeetingRoomApply.SQLCOL_TOPIC].ToString().Length > 100)
                dr[Wicresoft.Busi.Entity.MeetingRoomApply.SQLCOL_TOPIC] = dr[Wicresoft.Busi.Entity.MeetingRoomApply.SQLCOL_TOPIC].ToString().Substring(0, 26) + "...";
        }

        Pager.RecordCount = RecordCount;
        rptOrder.DataSource = dt;
        rptOrder.DataBind();
    }

    protected void rptProduct_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }


}
